var form;
var $;
var table;
layui.use(['form','jquery','table'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;

    //走请求查数据
    getAllCourseRecordData('', '', '', '');
});

function getAllCourseRecordData(tableName, type, createId){
    $.ajax({
        url: '/AuditLog/getAllTable',
        type: 'post',
        dataType: 'json',
        data: {
            'tableName': tableName,
            'type': type,
            'userId': createId,
        },
        success:function (item) {
            tab(item.data);
        }
    });
};

//展示表
function tab(data) {
    table.render({
        elem: '#demo' ,
        toolbar:'#toolutil',
        data: data,
        cols:[[
            {title:'序号', align:'center', templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'tableName',title:'审核类型', align:'center', templet:function (data) {
                    if (data.tableName == 2){
                        return '课程';
                    }else if (data.tableName == 3){
                        return '商品';
                    }else if (data.tableName == 4){
                        return '微圈';
                    }
                }},
            {field:'trueName',title:'审核人',align:'center'},
            {field:'type',title:'审核状态',align:'center', templet:function (data) {
                    if (data.type == 1){
                        return '未通过';
                    }else if (data.type == 2){
                        return '已通过';
                    }
                }},
            {field:'createDate',title:'审核时间',align:'center'},
            {field:'remark',title:'备注',align:'center'},
        ]]
    });
};


//刷新
function reload() {
    location.reload();
}

//搜索
function search() {
    var tableName = $('select[name=tableName]').val();
    var type = $('select[name=type]').val();
    var createName = $('input[name=createName]').val();
    var createId;
    if (createName != null && createName != ''){
        $.ajax({
            url: '/User/getByName',
            type: 'post',
            data: {'createName': createName},
            dataType: 'json',
            async: false,
            success:function (item) {
                createId = item.data;
            }
        });
        if (createId == null){
            createId = createName;
        }
    }
    console.log(tableName)
    console.log(type)
    console.log(createId)
    getAllCourseRecordData(tableName, type, createId);
};

function backOff() {
    var arr = localStorage.getItem("numArr");
    var numArr = arr.split(",");
    numArr.pop();
    window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
    localStorage.setItem("numArr",numArr);
};